﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net.Mail;

public partial class System_ExceptionTest : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
    }

    protected void RaiseException_Click(object sender, EventArgs e)
    {
        throw new ApplicationException("抛出用于测试的异常abcdefghijklmnopqrstuvwxyz");
    }
    protected void btnTestSendEmail_Click(object sender, EventArgs e)
    {
        MailMessage mm = new MailMessage("fengmk2@163.com", "fengmk2@gmail.com");

        mm.Subject = "test send email";
        mm.Body = "test end email body.";

        SmtpClient sc = new SmtpClient();

        // 编程方式设置smtp（不用web.config）
        // sc.Host = "";
        // sc.Port = 25;
        // sc.Credentials = new NetworkCredential("username", "password");

        sc.Send(mm);
        Response.Write("ok");

        //try
        //{
        //    sc.Send(mm);
        //    Response.Write("ok");
        //}
        //catch (Exception ex)
        //{
        //    // 与smtp相关的错误
        //    if (ex is SmtpException)
        //    {
        //        // ex.ToString();
        //        Response.Write("smtp发信失败");
        //    }
        //    else
        //    {
        //        Response.Write(ex.ToString());
        //    }
        //}
    }
    protected void RaiseSecurityException_Click(object sender, EventArgs e)
    {
        throw new System.Security.SecurityException("未获授权操作.");
    }
    protected void RaiseValidationException_Click(object sender, EventArgs e)
    {
        throw new Csla.Validation.ValidationException("数据验证失败.");
    }
    protected void RaiseDataPortalException_Click(object sender, EventArgs e)
    {
        throw new Csla.DataPortalException("数据访问失败.", sender);
    }
}
